<?php
// functions for events.
//___________________________________________________________________
require_once(e_PLUGIN.'ebattles/include/main.php');

class Gamer extends DatabaseTable
{
	protected $tablename = TBL_GAMERS;
	protected $primary_key = "GamerID";
}

function gamerEventSignupModalForm($event_id, $gamerID, $gamerName, $gamerUniqueGameID, $hide_password)
{
	// Modal form
	$text = '
	<div id="modal-form-signup" title="Sign Up">

	<!-- form validation error container -->
	<div class="ui-widget ui-helper-hidden" id="errorblock-div1">
	<div class="ui-state-error ui-corner-all" id="errorblock-div2" style="padding: 0pt 0.7em; display:none;">
	<p>
	<!-- fancy icon -->
	<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
	<strong>'.EB_GAMER_L1.'</strong> '.EB_GAMER_L2.'
	</p>
	<!-- validation plugin will target this UL for error messages -->
	<ul></ul>
	</div>
	</div>

	<!-- our form, no buttons (buttons generated by jQuery UI dialog() function) -->
	<form action="eventinfo_process.php?eventid='.$event_id.'" name="form-signup" id="form-signup" method="post">
	<div>
	<input type="hidden" name="joinevent" value=""/>
	<input type="hidden" name="gamerID" value="'.$gamerID.'"/>
	<fieldset>
	<legend>'.EB_GAMER_L3.'</legend>
	<p class="'.$hide_password.'">
	<label for="joinEventPassword">'.EB_EVENT_L27.'<span class="required">*</span></label>
	<input type="password" name="joinEventPassword" id="joinEventPassword" class="text '.$hide_password.'" />
	</p>
	<p>
	<label for="gamername">'.EB_GAMER_L4.'<span class="required">*</span></label>
	<input type="text" size="10" name="gamername" id="gamername" class="text required" value="'.$gamerName.'"/>
	</p>
	<p>
	<label for="gameruniquegameid">'.EB_GAMER_L5.'</label>
	<input type="text" size="10" name="gameruniquegameid" id="gameruniquegameid" class="text" value="'.$gamerUniqueGameID.'"/>
	</p>
	</fieldset>
	</div>
	</form>
	</div>';
	return $text;
}

function gamerDivisionSignupModalForm($clan_id, $div_id, $gamerID, $gamerName, $gamerUniqueGameID, $hide_password)
{
	// Modal form
	$text = '
	<div id="modal-form-signup" title="Sign Up">

	<!-- form validation error container -->
	<div class="ui-widget ui-helper-hidden" id="errorblock-div1">
	<div class="ui-state-error ui-corner-all" id="errorblock-div2" style="padding: 0pt 0.7em; display:none;">
	<p>
	<!-- fancy icon -->
	<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
	<strong>'.EB_GAMER_L1.'</strong> '.EB_GAMER_L2.'
	</p>
	<!-- validation plugin will target this UL for error messages -->
	<ul></ul>
	</div>
	</div>

	<!-- our form, no buttons (buttons generated by jQuery UI dialog() function) -->
	<form action="claninfo.php?clanid='.$clan_id.'" name="form-signup" id="form-signup" method="post">
	<div>
	<input type="hidden" name="division" value="'.$div_id.'"/>
	<input type="hidden" name="joindivision" value=""/>
	<input type="hidden" name="gamerID" value="'.$gamerID.'"/>
	<fieldset>
	<legend>'.EB_GAMER_L3.'</legend>
	<p class="'.$hide_password.'">
	<label for="joindivisionPassword">'.EB_CLAN_L11.'<span class="required">*</span></label>
	<input type="password" name="joindivisionPassword" id="joindivisionPassword" class="text required '.$hide_password.'" />
	</p>
	<p>
	<label for="gamername">'.EB_GAMER_L4.'<span class="required">*</span></label>
	<input type="text" size="10" name="gamername" id="gamername" class="text required" value="'.$gamerName.'"/>
	</p>
	<p>
	<label for="gameruniquegameid">'.EB_GAMER_L5.'</label>
	<input type="text" size="10" name="gameruniquegameid" id="gameruniquegameid" class="text" value="'.$gamerUniqueGameID.'"/>
	</p>
	</fieldset>
	</div>
	</form>
	</div>';
	return $text;
}


function updateGamer($user, $game, $Name, $UniqueGameID){
	global $tp;
	global $sql;
	
	$Name = $tp->toDB($Name);
	$UniqueGameID = $tp->toDB($UniqueGameID);

	$q = "SELECT ".TBL_GAMERS.".*"
	." FROM ".TBL_GAMERS
	." WHERE (".TBL_GAMERS.".Game = '".$game."')"
	."   AND (".TBL_GAMERS.".User = ".$user.")";
	$result = $sql->db_Query($q);
	$num_rows = mysql_numrows($result);
	if ($num_rows==0)
	{
		$q = " INSERT INTO ".TBL_GAMERS."(User,Game,Name,UniqueGameID)
		VALUES ($user, $game, '".$Name."', '".$UniqueGameID."')";
		$sql->db_Query($q);
		$gamerID = mysql_insert_id();
	}
	else
	{
		$gamerID =  mysql_result($result, 0, TBL_GAMERS.".GamerID");
		$q = "UPDATE ".TBL_GAMERS
		." SET UniqueGameID = '".$UniqueGameID."',"
		."     Name = '".$Name."'"
		." WHERE (GamerID = '".$gamerID."')";
		$sql->db_Query($q);
		$q = "UPDATE ".TBL_GAMERS." SET Name = '".$Name."' WHERE (GamerID = '".$gamerID."')";
		$sql->db_Query($q);
	}
	return $gamerID;
}


?>
